﻿using System;
using System.Collections;
using System.Collections.Generic;
using Me.Prettyprint.Cassandra.Connection;
using Me.Prettyprint.Cassandra.Service;
using Me.Prettyprint.Cassandra.Serializers;
using Me.Prettyprint.Cassandra.Utils;
using Me.Prettyprint.Hector.Api;
using Me.Prettyprint.Hector.Api.Beans;
using Me.Prettyprint.Hector.Api.Query;
using Org.Apache.Cassandra.Thrift;
using Thrift;

namespace Me.Prettyprint.Cassandra.Model
{
    /// <summary>
    /// Contains the results returned by get_slice query for supercolumns
    /// </summary>
    /// <typeparam name="SN"></typeparam>
    /// <typeparam name="N"></typeparam>
    /// <typeparam name="V"></typeparam>
    public class SuperSliceImpl<SN, N, V> : SuperSlice<SN, N, V>
    {
        public SuperSliceImpl(List<SuperColumn> tSuperColumns, Serializer<SN> sNameSerializer,
            Serializer<N> nameSerializer, Serializer<V> valueSerializer) 
        {
            if (tSuperColumns == null || sNameSerializer == null || nameSerializer == null || valueSerializer == null)
            {
                throw new NullReferenceException("SuperColumn, SuperName serializer, Name serializer and Value serializer cannot be null");
            }
            ColumnsDictionary = new Dictionary<SN,HSuperColumn<SN,N,V>>(tSuperColumns.Count);
            SuperColumns = new List<HSuperColumn<SN,N,V>>(tSuperColumns.Count);
            foreach (SuperColumn sc in tSuperColumns)
            {
                HSuperColumn<SN,N,V> column = new HSuperColumnImpl<SN,N,V>(sc, sNameSerializer, nameSerializer,
                    valueSerializer);
                ColumnsDictionary[column.Name] = column;
                SuperColumns.Add(column);
            }
        }

        protected Dictionary<SN, HSuperColumn<SN, N, V>> ColumnsDictionary
        {
            get;
            set;
        }
        public List<HSuperColumn<SN, N, V>> SuperColumns
        {
            get;
            protected set;
        }
        public HSuperColumn<SN, N, V> GetColumnByName(SN columnName)
        {
            return ColumnsDictionary[columnName];
        }
        public override string ToString()
        {
            return "SuperSlice(" + SuperColumns.ToString() + ")";
        }

    }
}
